// pages/book/book.js
import bookData from './data'
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    windowHeight: 0,
    screenHeight: 0,
    bd: bookData,
    answer: 'ANSWER',
    ststus: 0,
    loadingClass: ''
  },

  showAnswer: function () {
    var that = this

    if (that.data.ststus == 0) {

      that.setData({
        ststus: 1,
        loadingClass: 'loading'
      });

      var story = that.data.bd[Math.floor(Math.random() * that.data.bd.length)]

      var i = 1;
      var time = setInterval(function () {
        var text = story.substring(0, i);
        i++;
        that.setData({
          answer: text
        });
        if (text.length == story.length) {
          //   console.log("定时器结束！");
          clearInterval(time);
          that.setData({
            ststus: 0,
            loadingClass: ''
          });
        }
      }, 200)
    }


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    // console.log(that.data.bd)
    that.setData({
      windowHeight: app.globalData.windowHeight,
      screenHeight: app.globalData.screenHeight
    })

    console.log(app.globalData.windowHeight)
    console.log(app.globalData.screenHeight)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})